package shop;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.util.JRLoader;
import java.io.*;

public class FirstJasperReports {
    static String fileName="HelloWorld.jrxml";
    public static void main(String[] args)throws Exception{
        long startTime=System.currentTimeMillis();
        String jasperFile=JasperCompileManager.compileReportToFile(fileName);
        String jrprintFile=JasperFillManager.fillReportToFile(jasperFile,null,new JREmptyDataSource());

        JasperExportManager.exportReportToHtmlFile(jrprintFile);
    
        JasperExportManager.exportReportToPdfFile(jrprintFile);
   
        JasperExportManager.exportReportToXmlFile(jrprintFile,false);

        
        
        File sourceFile = new File(jrprintFile);
        JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
        File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls");
        JRXlsExporter exporter = new JRXlsExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
        exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
        exporter.exportReport();
        long endTime=System.currentTimeMillis();
        long time=(endTime-startTime)/1000;
        System.out.println("success with "+time+" s");
     }
}
